package com.shen.jcbf.strbf;


import org.apache.log4j.Logger;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class StringTest {

    private String aa;

    private static int num;
    private static Integer num1;

    private static Logger logger=Logger.getLogger(StringTest.class); // 获取logger实例

    public static void main(String[] args) {

//        int i = -1717986917;
//        int a =  2147483647;
//        int b = -2147483648;
//        int ab = 4294967296;
//        int ab = 2576980379;
//        int i = 858993461;

        /*System.out.println("-----------");
        System.out.println(getInt(2));
        System.out.println(getInt(1));
        System.out.println(getInt(0));
        System.out.println(getInt(-1));
        System.out.println(getInt(-2));
        System.out.println(getInt(-3));
        System.out.println("-----------");*/


        /*int a = 1;
        int b = 0;
        for(int i = 0;a != 0;i++){
            a = 5 * i + 3;
            b = i;
        }
        System.out.println(a + " —— " + b);*/


//        logger.info("普通Info信息");
//        logger. debug("调试debug信息");


        //test22();
        System.out.println("---" + "123".equals("456"));
        StringTest2.printValur(num + "");
    }


    public static int getInt(int result){
        int a = (result - 3) % 5;

        if(a == 0){
            return (result - 3) / 5;
        } else {

            //int的取值范围的个数的2倍
            long s = 8589934592L;
            Long l = null;

            if(a == 1 || a == -4){
                l = -(s/2 - result + 3) / 5;
            }else if(a == 2 || a == -3){
                l = -(s - result + 3) / 5;
            }else if(a == 3 || a == -2){
                l = (s + result - 3) / 5;
            }else if(a == 4 || a == -1){
                l = (s/2 + result - 3) / 5;
            }

            if(l != null) {
                return l.intValue();
            } else {
                return 0;
            }


            /*
            Long l1 = (s + result - 3) / 5;
            Long l2 = -(s - result + 3) / 5;
            Long l3 = (s/2 + result - 3) / 5;
            Long l4 = -(s/2 - result + 3) / 5;

            if(l1.intValue() * 5 == result - 3){
                System.out.println(a + "——1");
                return l1.intValue();
            }else if (l2.intValue() * 5 == result - 3){
                System.out.println(a + "——2");
                return l2.intValue();
            }else if (l3.intValue() * 5 == result - 3){
                System.out.println(a + "——3");
                return l3.intValue();
            }else if (l4.intValue() * 5 == result - 3){
                System.out.println(a + "——4");
                return l4.intValue();
            }else {
                return 0;
            }
            */
        }

    }

    public static void test22(){
        Map<Long,String> map = new HashMap<>();
        String s1 = "12";
        String s2 = "1234";
        String s3 = "34";
        String s5 = "1";
        String s6 = "234";
        map.put(Long.parseLong(s1 + s3),"bbb");
        map.put(Long.parseLong(s2),"aaa");
        System.out.println(map.get(Long.parseLong(s5 + s6)));

        List<String> collect = map.values()
                .stream()
                .collect(Collectors.toList());


    }

    public static void test21(){
        System.out.println("500".compareTo("400"));

        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        Date date = new Date(1524797645000L);
        System.out.println(sdf.format(date));
        System.out.println(sdf.toLocalizedPattern());
        System.out.println(sdf.toPattern());
    }
    public static void test20(){
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        Calendar cal=Calendar.getInstance();
        System.out.println(sdf.format(cal.getTime()));
        cal.add(Calendar.DATE,-3);
        System.out.println(sdf.format(cal.getTime()));
    }
    public static void test17(){
        List<Obj> list = new ArrayList<>();
        Obj o = new Obj();
        o.setTimeStr("11:11:11");
        list.add(o);

        o = new Obj();
        o.setTimeStr("12:11:11");
        list.add(o);

        o = new Obj();
        o.setTimeStr("11:13:11");
        list.add(o);

        list.forEach(System.out::print);

        list = list.stream().sorted((a,b) -> {
            return a.getTimeStr().compareTo(b.getTimeStr());
        }).collect(Collectors.toList());

        list.forEach(System.out::print);

    }
    public static void test15(){
        //Get the current date
        LocalDate date1 = LocalDate.now();
        System.out.println("Current date: " + date1);

        //add 1 month to the current date
        LocalDate date2 = date1.plus(3, ChronoUnit.DAYS);
        System.out.println("Next month: " + date2);

        Period period = Period.between(date1, date2);
        System.out.println("Period: " + period);
        System.out.println("Period.getYears: " + period.getYears());
        System.out.println("Period.getMonths: " + period.getMonths());
        System.out.println("Period.getDays: " + period.getDays());
    }

    public void test12(){
        //Arrays.asList("1","2").sort((e1,e2) -> e1.compareTo(e2));
        //Arrays.asList("1","2").forEach(e -> System.out.println(e));

//        StringTest functionTest = new StringTest();
//        System.out.println(functionTest.compute1(5,i -> i * 2,i -> i * i));//50
//        System.out.println(functionTest.compute2(5,i -> i * 2,i -> i * i));//100




//        String[] array = {"gjyg", "ads", "jk"};
//        Arrays.sort(array, String::compareToIgnoreCase);
//
//        Arrays.sort(array);



//        List<String> li = Arrays.asList("2","3","5");
//        Optional<String> min = li.stream().min((a, b) -> a.compareTo(b));
//        System.out.println(min.get());

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);
    }
    public void test11(){
        Function function = new Function() {
            @Override
            public Object apply(Object o) {
                return o.toString() + "-----";
            }
        };

        Function<String,String> function2 = new Function() {
            @Override
            public Object apply(Object o) {
                return "-----" + o.toString();
            }
        };



        Function compose = function.compose(e -> {return "-----" + e.toString();});
        System.out.println(compose.apply("11"));
    }

    public int compute1(int i, Function<Integer,Integer> after, Function<Integer,Integer> before){
        return after.compose(before).apply(i);
    }

    public int compute2(int i, Function<Integer,Integer> before,Function<Integer,Integer> after){
        return before.andThen(after).apply(i);
    }

    public static void test(){
        int ii = 5;
        Integer aa = 5;
        System.out.println(ii == aa);

        String s1 = "10:00:00";
        String s2 = "12:00:00";
        System.out.println(s2.compareTo(s1));
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s1));

        Time t = new Time(new Date().getTime());
        System.out.println(t);

        String str1 = getData("");
        System.out.println(str1);
    }
    public static String getData(String s1){
        return s1 + "--";
    }

    static class Obj{
        private String timeStr;

        public String getTimeStr() {
            return timeStr;
        }

        public void setTimeStr(String timeStr) {
            this.timeStr = timeStr;
        }

        @Override
        public String toString() {
            return "Obj{" +
                    "timeStr='" + timeStr + '\'' +
                    '}';
        }
    }


}

